/*
 * @Author: your name
 * @Date: 2020-10-19 17:46:54
 * @LastEditTime: 2020-10-26 10:49:41
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /Project/node/routes/Food.js
 */
const express = require('express');
const router = express.Router();
const { body } = require('express-validator');
const service = require('../services/FoodService');
const uploadservice = require('../services/FileUploadService')

const moment = require('moment');
const path = require('path')


var timestamp = '';
var timepath = moment().format('YYYY-MM-DD');
var destination = '/upload';
var filename = '';


var multer = require('multer');
 var storage = multer.diskStorage({
     //这里destination是一个字符串
    destination: '.' + destination,
    //这里直接忽略文件的后缀.
     filename: function (req, file, cb) {
         var date = new Date();
         cb(null, moment().format("YYYY-MM-DD-hhmmss") + file.originalname);
     }
 });
 let upload = multer({storage : storage });
// 录入商品
const vaildator = [
    
]

// 录入商品路由
router.post('/commitfood',vaildator, service.commitFood);

// 获取商品列表路由
router.post('/foodList',vaildator, service.foodList);


// 获取单个商品详情信息
router.post('/singleGoodDetail',vaildator, service.goodDetail);





// 单个图片上传
router.post('/uploads', upload.single('file'), function (req, res, next) {
    var fileName = req.file.filename;
    if (fileName) {
        res.json({code:200,data:{imageName:fileName},msg:'上传成功'})
    }
})
// 图片显示
router.get('/showImage/upload/*', function (req, res) {
    var dest_Dir = path.join(__dirname.replace("node/routes", "/upload"),req.params['0']);
    res.sendFile(dest_Dir)
})


module.exports = router;